﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

<script type="text/javascript">
    $(function() {
        $.ajax({
            type: "POST",
            url: "/Basic/SortedUserList",
            success: function(data) {
                $("#soredLand").append(data);
            }
        })
    })

    function changeDept() {
        var deptId = $("#dept").val();
        if (deptId == "1") {
            alert("不能将员工移至公司部门");
            return;
        }

        var table = $("#alluserlist").children("div").children("table");
        var trcontent = $(table).children().children(".tbcontent");
        var ids = "";
        //alert(trcontent.length);
        $.each(trcontent, function(key, value) {
            var tdname = $(value).children(".tdname"); ;
            var check = $(tdname).children(".checkname").attr("checked");
            if (check == true) {
                var id = $(tdname).children(".hideid").val();
                //alert(id);
                ids += "'" + id + "',";
            }
        })
        
        if (ids == "") {
            alert("请先勾选需要迁移部门的员工");
            return;
        }

        $.ajax({
            type: "POST",
            url: "/Basic/ChangeDept",
            data: { "userIds": ids, "deptId": deptId },
            success: function(restag) {
                if (restag.res != true) {
                    alert(restag.msg);
                    return;
                }
                else {
                    alert("操作成功");
                    $('#menu_userlist').trigger('click');
                }
            }
        });
    }
</script>

<div id="soredLand" style="padding-top: 45px;">
    <%using (Ajax.BeginForm("SortedUserList", "Basic", new AjaxOptions { UpdateTargetId = "alluserlist" }))
      { %>
    用户名:<%=Html.TextBox("userName")%>
    创建时间:<%=Html.TextBox("createtime")%>
    部门名称:<%=Html.TextBox("deptName")%>
    <input type="submit" value="查询" />
    <%} %>
    <br />
    <input type="button" onclick="changeDept()" value="部门迁移至" />
    <%=Html.DropDownList("dept")%>
</div>
